/**************************************************
|	File:		CMagicProjectile.cpp
|	Author:		Benjamin Budian
|	Course:		SGD
|	Purpose:	MagicProjectile is a ball of energy fired from an entity
**************************************************/
#include "MagicProjectile.h"
#include "CellAnimation.h"

#include "../SGD Wrappers/CSGD_Direct3D.h"
#include "../SGD Wrappers//CSGD_EventSystem.h"
#include "../SGD Wrappers/SGD_String.h"

CMagicProjectile::CMagicProjectile(int nFrameID) : CProjectile(nFrameID)
{
	m_fDamage		= 20;
	m_nNumCols		= 4;
	m_nFrameWidth	= 32;
	m_nFrameHeight	= 32;
	m_nCurrentFrame = nFrameID;

	m_bDebug = false;

	SetWidth(16);
	SetHeight(13);

	m_pOwner = nullptr;

	m_eType = ENT_MAGIC_PROJECTILE;

	m_MagicAnimation = new CCellAnimation();

	m_MagicAnimation->Initialize(m_nFrameWidth,m_nFrameHeight,4,0,4,true,_T("resource/images/Player/Projectiles/bb_plasmaballlpc_0.png"));
	
	m_MagicAnimation->Play(true, 1.0f);
}

CMagicProjectile::~CMagicProjectile(void)
{
	CSGD_EventSystem::GetInstance()->UnregisterClientAll(this);
	delete m_MagicAnimation;
}

void CMagicProjectile::Update( float fElapsedTime ){
	m_MagicAnimation->Update(fElapsedTime);

	CEntity::Update(fElapsedTime);
}

void CMagicProjectile::Render(){
	if(m_bDebug){
		RECT rCollisionBox = GetRect();
		CSGD_Direct3D::GetInstance()->DrawRect(rCollisionBox, D3DCOLOR_ARGB(127,255,255,0));

		TOSTRINGSTREAM toss;

		toss << "(" << GetPosX() << ", " << GetPosY() << ")\n"
			<< "Projectile Type: " << GetType() << '\n'
			<< "Damage: " << m_fDamage << '\n';

		CBitmapFont* pFont = CGame::GetInstance()->GetFont();

		pFont->Draw(toss.str().c_str(),(int)(GetPosX() + GetWidth()), (int)(GetPosY()), .34f,D3DCOLOR_ARGB(255,0,0,0));

	}
	m_MagicAnimation->Render((int)GetPosX(), (int)GetPosY(), 1.0f, D3DCOLOR_ARGB(255,255,255,255));
}

void CMagicProjectile::SetOwner(CEntity* pOwner){
	if(m_pOwner != nullptr)
		m_pOwner->Release();
	
	m_pOwner = pOwner;

	if(m_pOwner != nullptr)
		m_pOwner->AddRef();
}

void CMagicProjectile::HandleEvent( CEvent* pEvent ){
	if(pEvent->GetEventID() == "DEBUG")
		m_bDebug = !m_bDebug;
}





